﻿<!DOCTYPE>

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>新收料确认</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style>
        .easyui-linkbutton{margin-left:20px;}
        table tr td{padding:0px 5px}
        .tip{line-height: 25px;
            height: 25px;
            display: inline-block;
            vertical-align: middle;
            padding: 0 10px;}
    </style>
</head>
<body>
    <div class="panelSection">    
        <div class="easyui-panel " title="查询区域" style="padding:3px;width:100%" 
        data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
           <form id="searchForm" method="post">
	    	<table>
	    		<tr  class="divLabel">
                    <td>发动机号</td>
                    <td>订单号(起)</td>
                    <td>订单号(止)</td>
                    <td>订单类型</td>
                    <!--<td>状态</td>-->
                    <td>订单状态:</td>
	    		</tr>
	    		<tr >
	    			<td><input class="easyui-textbox" type="text" name="Machine" style="width: 120px; height: 22px"/></td>
                    <td><input class="easyui-textbox" type="text" name="mfgOrderName" style="width: 120px; height: 22px"/></td>
                    <td><input class="easyui-textbox" type="text" name="mfgOrderNameLast" style="width: 120px; height: 22px"/></td>
	    			<td><input id="OrderType" name="OrderTypeIndex" style="width: 120px; height: 22px"/></td>
                   <!-- <td><input id="OrderStatus" name="OrderStatus" style="width: 120px; height: 22px"/></td>-->
                    <td>
                        <select name="OrderCloseStatus" class="easyui-combobox" style="width:100px;height: 22px" data-options="panelHeight:'auto'">
                            <option value="" selected>全部</option>
                            <option value="0">打开</option>
                            <option value="1">关闭</option>
                        </select>
                    </td>
                    <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchData()">查询</a></td>
	    			<td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchReset()">重置</a></td>
	    		</tr>
	    	</table>
	    </form>
        </div> 
    </div>
   <!-- ------------内容显示区域------------------>
      <div class="panelSection">    
        <div class="easyui-panel " title="任务单信息" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
        <table id="gdContainerInfo" style="width: 100%; height: 230px" data-options="rownumbers:true,pagination:false,striped:true,checkOnSelect:true,selectOnCheck:true,singleSelect:false,pageNumber:1,pageSize:5,pageList:[5,10,20]"></table>
        <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                    buttons:[{
                            iconCls:'',
                            text:'Go',
                            id:'pageGo'
                    }]  
                ">
          </div>
        </div>
      </div>
    <div class="panelSection">    
        <div class="easyui-panel BigSmallTable" title="物料信息" style="padding:3px;width:100%" 
        data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
            <table id="MaterialTable" style="height: 350px;width:100%" data-options="rownumbers:true,pagination:false,striped:true,checkOnSelect:true,selectOnCheck:true,singleSelect:false"></table>
            <div id="ppp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                    buttons:[{
                            iconCls:'',
                            text:'Go',
                            id:'pageGoo'
                    }]  
                ">
          </div>
     </div>
   </div>
      <div class="panelSection">    
        <div class="easyui-panel " title="按钮区域" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.BatchReciveMaterialListCofirm()" style="margin: 10px 0 10px 20px;">批量收料确认</a>
            <span style="background-color:rgb(149, 242, 2);margin-left:100px" class="tip">ERP总数量 >= 需求数量</span>
            <span style="background-color:rgb(236, 128, 141)" class="tip">ERP总数量 < 需求数量</span>
        </div>
      </div>
     <!--信息提示区域-->
    <div id="statusMessage" style="font-size: 14px; height: 40px"></div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script >
    /*
    创建人：longb
    日期：2023-04-04
    描述：新收料确认js
    */
    var page = {
        pagetotal: 0,
        pageSize: 20,
        pageNumber: 1,
        pagetotal1: 0,
        pageSize1: 200,
        pageNumber1: 1,
        editIndex: null, //easyUI单元格编辑
        oldeditIndex: null,
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSReciveMaterialConfirmHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();
            customizedEasyuiPagination('pp'); //定制化分页
            customizedEasyuiPagination('ppp'); //定制化分页
            page.addEditCell();
        },
        addEditCell: function () //给easyuigrid新增editcell方法
        {
            $.extend($.fn.datagrid.methods, {
                editCell: function (jq, param) {
                    return jq.each(function () {
                        var opts = $(this).datagrid('options');
                        var fields = $(this).datagrid('getColumnFields', true).concat($(this).datagrid('getColumnFields'));
                        for (var i = 0; i < fields.length; i++) {
                            var col = $(this).datagrid('getColumnOption', fields[i]);
                            col.editor1 = col.editor;
                            if (fields[i] != param.field) {
                                col.editor = null;
                            }
                        }
                        $(this).datagrid('beginEdit', param.index);
                        for (var i = 0; i < fields.length; i++) {
                            var col = $(this).datagrid('getColumnOption', fields[i]);
                            col.editor = col.editor1;
                        }
                    });
                }
            });
        },
        endEditing: function (gridId) {
            if (page.editIndex == undefined) { return true }
            if ($('#' + gridId).datagrid('validateRow', page.editIndex)) {
                $('#' + gridId).datagrid('endEdit', page.editIndex);
                page.editIndex = undefined;
                return true;
            } else {
                return false;
            }
        },
        formatDate: function (value, row, index) {
            var date = new Date(value);
            if (navigator.userAgent.indexOf("MSIE") > -1) { date = new Date(value.replace(/-/g, '/')); }
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            var h = date.getHours();
            return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
        },
        formatStyle: function (value, row, index) {
            if ((row.ERPTOTALQTY >= row.NEEDQTY)) { return 'background-color:rgb(149, 242, 2)'; } else { return 'background-color:rgb(236, 128, 141)'; }
        },
        mergeCellsByField: function (tableID, colList) {
            var ColArray = colList.split(",");
            var tTable = $("#" + tableID);
            var TableRowCnts = tTable.datagrid("getRows").length;
            var tmpA;
            var tmpB;
            var PerTxt = "";
            var CurTxt = "";
            var alertStr = "";
            for (j = ColArray.length - 1; j >= 0; j--) {
                PerTxt = "";
                tmpA = 1;
                tmpB = 0;
                for (i = 0; i <= TableRowCnts; i++) {
                    if (i == TableRowCnts) {
                        CurTxt = "";
                    }
                    else {
                        CurTxt = tTable.datagrid("getRows")[i][ColArray[j]];
                    }
                    if (PerTxt == CurTxt && CurTxt!=null) {
                        tmpA += 1;
                    }
                    else {
                        tmpB += tmpA;
                        tTable.datagrid("mergeCells", {
                            index: i - tmpA,
                            field: ColArray[j], //合并字段
                            rowspan: tmpA,
                            colspan: null
                        });
                        var arr = "ck,PARTTYPE,ERPTOTALQTY,QTY,CONFIRMQTY,QTL,NEEDQTY";
                        $.each(arr.split(','), function (index, item) {
                            tTable.datagrid("mergeCells", { //根据ColArray[j]进行合并
                                index: i - tmpA,
                                field: item,
                                rowspan: tmpA,
                                colspan: null
                            });
                        });
                        tmpA = 1;
                    }
                    PerTxt = CurTxt;
                }
            }
        },

        //页面事件绑定
        bind: function () {
            $('#OrderType').combobox({
                data: [{ id: 0, text: '常规生产订单' }, { id: 1, text: '无物料号订单'}],
                valueField: 'id',
                textField: 'text',
                value: 0
            });
            $('#OrderStatus').combobox({
                data: [{ id: 1, text: '未分解' }, { id: 2, text: '已分解'}],
                valueField: 'id',
                textField: 'text',
                value: 1
            });
            //任务单信息
            $("#gdContainerInfo").datagrid({
                singleSelect: true,
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pagetotal,
                        pageSize: page.pageSize,
                        pageNumber: page.pageNumber
                    });
                    customizedEasyuiPagination('pp'); //定制化分页
                },
                onSelect: function (index, rowData) { page.GetMaterialListData(); },
                onUnselect: function (index, rowData) { page.GetMaterialListData(); },
                columns: [[
                 { field: 'MFGORDERNAME', title: '生产订单号', width: 150 },
		         { field: 'ORDERTYPENAME', title: '订单类型', width: 100 },
		         { field: 'MFGTYPE', title: '订单类别', width: 90 }, //--
                 {field: 'QTY', title: '订单数', width: 90 },
                 { field: 'ENGINENO', title: '发动机号', width: 90 },
                 { field: 'PRODUCTNAME', title: '物料号', width: 120 },
                 { field: 'PRODUCTDESCRIPTION', title: '物料描述', width: 120 },
                 { field: 'PRODUCTFAMILYNAME', title: '机型', width: 120 },
                 { field: 'PLANNEDSTARTDATE', title: '计划开始日期', width: 130, formatter: page.formatDate },
                 { field: 'PLANNEDCOMPLETIONDATE', title: '计划完成日期', width: 130, formatter: page.formatDate },
                 { field: 'QTL', title: '预齐套率', width: 90, align: 'center', hidden: true, formatter: function (value, row, index) {
                     if (value >= 1) { return '<span style="color:#0000ff">100%</span>'; } else { return '<span style="color:red">' + (parseInt(value * 100)) + '%</span>'; }
                 }
                 }
	           ]]
            });

            //物料信息
            $('#MaterialTable').datagrid({
                checkOnSelect: false,
                selectOnCheck: false,
                singleSelect: true,
                striped: false,
                onLoadSuccess: function (data) {
                    
                },
                columns: [[
                    { field: 'ck', title: '选择', checkbox: true },
		            { field: 'PRODUCTNAME', title: '件号', width: 100 },
		            { field: 'PRODUCTDESC', title: '件号名称', width: 200 },
                    { field: 'PARTTYPE', title: '零件类型', width: 100, align: 'center', formatter: function (value, row, index) { if (value == "0") { return '大件'; } else { return '小件'; } } },
		            { field: 'NEEDQTY', title: '需求数量', width: 100, align: 'center' },

                    { field: 'QTY', title: '本次收料数量', width: 130, align: 'center', editor: { type: 'numberbox' }, styler: page.formatStyle
                        , formatter: function (value, row, index) { if (value < 0) { return 0; } else { return value; } }
                    },
                    { field: 'ERPTOTALQTY', title: 'ERP总数量', width: 90, align: 'center' },
                    { field: 'PRODUCTBATCHNO', title: 'ERP批次', width: 100, align: 'center' },
                    { field: 'ERPQTY', title: 'ERP批次数量', width: 100, align: 'center' },
                    { field: 'CONFIRMQTY', title: '已收料数量', width: 90, align: 'center' },
                    { field: 'QTL', title: '预齐套率', width: 90, align: 'center', formatter: function (value, row, index) {
                        var c =(row.NEEDQTY==0||row.NEEDQTY==undefined)?0:row.CONFIRMQTY / row.NEEDQTY; if (c >= 1) { return '<span style="color:#0000ff">' + parseInt(c * 100) + '%</span>'; } else { return '<span style="color:red">' + parseInt(c * 100) + '%</span>'; }
                    }
                    }
                //{ field: 'OP', title: '操作', width: 100, align: 'center', formatter: function (value, row, index) { return '<a href="javascript:void(0)" class="easyui-linkbutton l-btn" style="text-decoration:none;padding: 0 10px;" onclick="page.BatchReciveMaterialCofirm(\'' + index + '\')">收料确认</a>' } }
                ]],
                onClickCell: function (index, field, value) {
                    page.oldeditIndex = page.editIndex;
                    if (value > 0 && field == "QTY") {
                        if (page.endEditing('MaterialTable')) {
                            $('#MaterialTable').datagrid('editCell', { index: index, field: field });
                            var editor = $(this).datagrid('getEditor', { index: index, field: field }); //获取当前编辑器
                            $(editor.target).next().find('.validatebox-text').focus();
                            page.editIndex = index;
                        }
                    } else {
                        if (page.editIndex != null) { $('#MaterialTable').datagrid('endEdit', page.editIndex); }
                    }
                },
                onAfterEdit: function (index, row, changes) {
                    if (row.NEEDQTY < Number(changes.QTY) + Number(row.CONFIRMQTY)) {
                        $.messager.confirm('提示', '本次收料数量+已收料数量>需求数量，是否继续？', function (r) {
                            if (r)//继续执行
                            {
                                $('#MaterialTable').datagrid('updateRow', { index: page.oldeditIndex, row: { QTY: changes.QTY} });
                                //page.mergeCellsByField("MaterialTable", "PRODUCTNAME,PRODUCTDESC");
                            } else {
                                $('#MaterialTable').datagrid('updateRow', { index: page.oldeditIndex, row: { QTY: row.NEEDQTY - row.CONFIRMQTY} });
                                //page.mergeCellsByField("MaterialTable", "PRODUCTNAME,PRODUCTDESC");
                            }
                        });
                        //page.mergeCellsByField("MaterialTable", "PRODUCTNAME,PRODUCTDESC");
                    } else {
                        //page.mergeCellsByField("MaterialTable", "PRODUCTNAME,PRODUCTDESC");
                    }
                },
                onLoadSuccess: function (data) {
                    if (data.rows.length > 0) {
                        //page.mergeCellsByField("MaterialTable", "PRODUCTNAME,PRODUCTDESC");
                    }
                    $('#ppp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pagetotal1,
                        pageSize: page.pageSize1,
                        pageNumber: page.pageNumber1
                    });
                    customizedEasyuiPagination('ppp'); //定制化分页
                }
            });
            //分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize = pageSize; page.pageNumber = pageNumber;
                    page.GetMfgOrderData();
                }
            });
            $('#ppp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize1 = pageSize; page.pageNumber1 = pageNumber;
                    page.GetMaterialListData();
                }
            });
            //绑定分页go按钮
            $('#pageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber = pageNumber;
                page.GetMfgOrderData();
            });
            $('#pageGoo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber1 = pageNumber;
                page.GetMaterialListData();
            });
            //清除按钮
            $('#btnReset').on("click", function () {
                page.reset(true, true);
                page.pageNumber = 1; page.pagetotal = 0
                $('#pp').pagination('refresh', {
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
            });


        },
        //查询
        searchData: function () {
            page.reset(false, true);
            page.pageNumber = 1;
            $('#MaterialTable').datagrid('loadData', []);
            page.GetMfgOrderData();
        },
        //查询订单信息
        GetMfgOrderData: function () {
            $('#MaterialTable').datagrid('loadData', [])
            var frdata = $('#searchForm').serializeArray();
            var data = {OrderStatus:'2'};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
            var param = {
                action: "GetMfgOrderData",
                pageSize: page.pageSize,
                pageNumber: page.pageNumber,
                data: JSON.stringify(data)
            };
            page.post(param, function (res) {
                if (res.Result) {
                    //                console.info(res);
                    page.pagetotal = res.RowCount;
                    $('#gdContainerInfo').datagrid('loadData', res.DBTable)
                }
            });
        },
        //整台发动机物料信息
        GetMaterialListData: function () {
            $('#MaterialTable').datagrid('loadData', []);
            var row = $('#gdContainerInfo').datagrid('getSelected');
            var param = {
                action: "GetMaterialListData",
                data: JSON.stringify(row),
                pageSize: page.pageSize1,
                pageNumber: page.pageNumber1,
            };
            page.post(param, function (res) {
                page.pagetotal1 = res.RowCount;
                $('#MaterialTable').datagrid('loadData', res.DBTable)
            });

        },
        //查询重置
        searchReset: function () {
            $('#searchForm').form('clear');
            page.bind();
        },
        //批量报工
        BatchReciveMaterialListCofirm: function (index) {
            var rows = $('#MaterialTable').datagrid('getChecked');
            if (index != null) {
                rows = [$('#MaterialTable').datagrid('getRows')[index]];
            }
            //        console.info(rows);
            var row = $('#gdContainerInfo').datagrid('getSelected');
            var param = {
                action: "ReciveMaterialListCofirm",
                data: JSON.stringify(rows),
                mfgorderid: row.MFGORDERID
            };
            if (rows.length == 0) {
                displayMessage("请先选择对应物料信息，再进行确认");
                return;
            }
            page.post(param, function (res) {
                if (res.Result) {
                    page.GetMaterialListData();
                }
                displayMessage(res.Message, res.Result);
            });

        },
        LookCollecterpmaterialData: function (index) {
           var row = $('#gdContainerInfo').datagrid('getRows')[index];
        },
        //清除方法，重要！！！
        reset: function (iscondition, isresult) {
            clearMessage();
        },
        //post数据
        post: function (param, callback) {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        }
    }
    $(function () {
        page.init();
    });

</script>
